package com.kate.order.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kate.order.entity.Order;
import com.kate.order.mapper.OrderMapper;
import com.kate.order.response.ServerResponse;
import com.kate.order.service.IOrderService;
import com.kate.order.servlet.ListOrderServlet;
import com.kate.order.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.util.List;

/**
 * @author 新梦想.陈超
 * @version 2021.2
 * @Description: {TODO}
 * @date 2023/7/10 下午3:19
 */

public class OrderServiceImpl implements IOrderService {

    private Logger log = Logger.getLogger(OrderServiceImpl.class);
    @Override
    public ServerResponse list(int page, int limit) throws Exception {
        //TODO 1.处理参数

        //TODO 2.调用Mapper查询数据
        final SqlSession sqlSession = SqlSessionUtil.init();
        final OrderMapper orderMapper = sqlSession.getMapper(OrderMapper.class);
        PageHelper.startPage(page,3);
        List<Order> orderList = orderMapper.selectByExample(null);
        log.debug("通过orderMapper查询的分页数据为："+ orderList);
        //TODO 3.返回Model（数据）-----java 集合------>json数组
        ServerResponse serverResponse = new ServerResponse();
        serverResponse.setCode(0);
        serverResponse.setMsg("success");
        serverResponse.setCount(new PageInfo<Order>(orderList).getTotal());
        serverResponse.setData(orderList);
        return serverResponse;
    }
}
